package cn.lopr.im.api.common;


import java.io.Serializable;

/**
 * @author shuangyang7
 * @date 2020/12/28 14:55
 */

public class CallbackMessage<T> implements Serializable {

    private int status;

    private String msg;

    private T data;

    public CallbackMessage() {
    }

    public CallbackMessage(int status) {
        this.status = status;
    }

    private CallbackMessage(int status, T data) {
        this.status = status;
        this.data = data;
    }

    private CallbackMessage(T data) {
        this.status = Constant.ResponseCode.SUCCESS.getCode();
        this.data = data;
    }

    private CallbackMessage(int status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public CallbackMessage(int status, String msg, T data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> CallbackMessage<T> createBySuccess() {
        return new CallbackMessage<>(Constant.ResponseCode.SUCCESS.getCode());
    }

    public static <T> CallbackMessage<T> createBySuccess(String msg) {
        return new CallbackMessage<>(Constant.ResponseCode.SUCCESS.getCode(), msg);
    }

    public static <T> CallbackMessage<T> createBySuccess(T data) {
        return new CallbackMessage<>(data);
    }

    public static <T> CallbackMessage<T> createBySuccess(String msg, T data) {
        return new CallbackMessage<>(Constant.ResponseCode.SUCCESS.getCode(), msg, data);
    }

    public static <T> CallbackMessage<T> createByError() {
        return new CallbackMessage<>(Constant.ResponseCode.ERROR.getCode(), Constant.ResponseCode.ERROR.getDesc());
    }

    public static <T> CallbackMessage<T> createByError(String msg) {
        return new CallbackMessage<>(Constant.ResponseCode.ERROR.getCode(), msg);
    }

    public static <T> CallbackMessage<T> createByError(String msg, T data) {
        return new CallbackMessage<>(Constant.ResponseCode.ERROR.getCode(), Constant.ResponseCode.ERROR.getDesc(), data);
    }

    public static <T> CallbackMessage<T> createByError(int errorCode, String errorMessage) {
        return new CallbackMessage<>(errorCode, errorMessage);
    }

    public static <T> CallbackMessage<T> createByErrorCode(int errorCode) {
        return new CallbackMessage<>(errorCode, Constant.ResponseCode.getDescByCode(errorCode));
    }

    @Override
    public String toString() {
        return "Message{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                ", data=" + data.toString() +
                '}';
    }
}
